import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:kkhousekeep/page/login/login_controller.dart';
import 'package:kkhousekeep/page/me/about_controller.dart';

import '../../widget/custom_app_bar.dart';
import '../../widget/setting_section.dart';

class About extends StatelessWidget {
  const About({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AboutController>(
      init: AboutController(),
      builder: (controller) => Scaffold(
        appBar: CustomAppBar("关于"),
        body: Container(
          color: const Color(0xFFf4f5f6),
          child: SafeArea(
            left: false,
            right: false,
            child: Obx(
              () => controller.userType.value == UserType.property
                  ? generatePropertyView(controller)
                  : generateClientView(controller),
            ),
          ),
        ),
      ),
    );
  }

  Column generateClientView(AboutController controller) {
    return Column(
      children: [
        _buildAppLogo(),
        _buildAppName(controller),
        _buildVersionName(controller),
        _buildSectionList(controller),
        const Spacer(),
        _buildContact(controller),
      ],
    );
  }

  Column generatePropertyView(AboutController controller) {
    return Column(
      children: [
        Container(
          width: double.infinity,
          height: 296.h,
          color: Colors.white,
          child: Center(
            child: Image(
              width: 315.w,
              height: 38.h,
              fit: BoxFit.contain,
              image: const AssetImage("assets/images/icon_konka_logo.png"),
            ),
          ),
        ).marginOnly(top: 16.h),
        SettingSectionItem(
          height: 140.h,
          title: "公司简介\n",
          textAlign: TextAlign.end,
          content: "深圳康佳电子科技有限公司\n(www.konka.com)",
          isShowArrow: false,
        ).marginOnly(top: 16.h),
        const SettingSectionItem(
          title: "联系方式",
          content: "0755-86710900",
          textAlign: TextAlign.end,
          isShowArrow: false,
        )
      ],
    );
  }

  Widget _buildAppLogo() {
    return Padding(
      padding: EdgeInsets.only(top: 84.h, bottom: 24.h),
      child: Image(
        width: 96.w,
        height: 96.h,
        image: const AssetImage("assets/images/me_about_logo.png"),
      ),
    );
  }

  Widget _buildAppName(AboutController controller) {
    return Obx(
      () => Text(
        controller.appName.value,
        style: TextStyle(
          fontSize: 32.sp,
          color: const Color(0xFF434649),
        ),
      ),
    );
  }

  Widget _buildVersionName(AboutController controller) {
    return Padding(
      padding: EdgeInsets.only(top: 6.h, bottom: 48.h),
      child: Obx(
        () => Text(
          controller.versionName.value,
          style: TextStyle(
            fontSize: 24.sp,
            color: const Color(0xFFC6C9CC),
          ),
        ),
      ),
    );
  }

  Widget _buildSectionList(AboutController controller) {
    return ListView(
      shrinkWrap: true,
      children: const [
        SettingSectionItem(title: "康佳账号服务条款"),
        SettingSectionItem(title: "用户协议与隐私政策")
      ],
    );
  }

  Widget _buildContact(AboutController controller) {
    return Padding(
      padding: EdgeInsets.only(bottom: 60.h),
      child: Text("联系方式 0755-86710900\n深圳康佳电子科技有限公司版权所有",
          style: TextStyle(
              fontSize: 28.sp, color: const Color(0xFF999999), height: 1.5),
          textAlign: TextAlign.center),
    );
  }
}
